IE Contract Spec (1)

Overview

This is a Meridian Impact Evaluator Contract.

Data model

Round

The Round struct will be used to define all the measurements and evaluations that occur as part of a IE round.

Round contains three variables:

  • measurementCids: defines a list of cids, each cid being the root CID of a merkle tree of measurements submitted by an arbitrary measurement service that has access to the IE.
  • participants: defines a list participants of this IE round.
  • scores: scores for each participant matched by index.

  struct Round {
        string[] measurementCids;
	      address payable[] participants;
				uint64[] scores;
    }

Variables

maxStoredRounds

An public unsigned integer that determines the maximum number of stored rounds that the contract retains.

EVALUATE_ROLE

A public constant bytes32 access control role that grants participants the ability to trigger evaluations.

MEASURE_ROLE

A public constant bytes32 access control role that grants participants the ability to submit measurements to the contract

rounds

The list of Round structs that the contract maintains

roundCounter

A uint256 that stores the round counter

Functions

constructor

constructor(address admin)

The constructor for the contract. It should assign the admin to all the available roles that exist on the contract.

addMeasurement

addMeasurement (bytes32 memory cid) public returns (uint)

Submits a measurement to the contract which gets added to the current Round’s measurementCid list. Returns the round number that the measurement was inserted in.

Round numbers are used so participants can know which measurements to run proofs of inclusion against.

submitEvaluationScores

submitEvaluations (
	uint256 roundIndex,
	address payable[] memory adresses,
	uint256[] memory scores
) public returns (uint)

Submits evaluation scores for the a given IE round. The submission of scores trigger rewards.

The IE should check if the round length exceeds the max allowable stored rounds and call a function to modify it.

reward

reward (
	address payable[] memory addresses,
  uint[] memory scores
) public returns (uint)

Reward will initialize a separate rewards contract that sends the FIL to each address.

TODO: define Reward contract

advanceRound

function advanceRound() public

This function increases roundCounter by 1, adds a new Round to the rounds array and emits a RoundStart event.

Getters

currentRoundIndex

function currentRoundIndex() public view returns (uint) {
        return rounds.length - 1;
 }

getRound

function getRound(uint index) public view returns (Round memory) {
        return rounds[index];
}

TODO add function to cleanup rounds.

TODO Add getter for participant data.

Setters

setMaxStoredRounds

function setMaxStoredRounds(uint max) public {
	 require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Not an admin");
	 maxStoreRounds = max
}

Events

MeasurementAdded

Puts Measurement events on chain

EvaluationsAdded

Puts evaluation events on chain

RoundStart

Signals start of a new round, end of the previous round.